<template>
  <div class="app">
    <div class="shell">
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
    </div>
  </div>
</template>

<script setup name="MouseFollow">
import { onMounted } from "vue"

const info = () => {
  document.addEventListener("mousemove", (e) => {
    const item = document.querySelectorAll(".item");

    const mouseX = e.clientX;
    const mouseY = e.clientY;

    item.forEach((sqr) => {
      const sqrX = sqr.offsetLeft;
      const sqrY = sqr.offsetTop;

      const diffX = mouseX - sqrX;
      const diffY = mouseY - sqrY;

      const radians = Math.atan2(diffY, diffX);

      const angle = (radians * 180) / Math.PI;

      sqr.style.transform = `rotate(${angle}deg)`;
    });
  });
}

onMounted(()=>{
  info();
})
</script>

<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
}

.app {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  // background-color: #eed9eba9;
}
.shell {
  display: grid;
  grid-template-columns: repeat(7, 40px);
  grid-template-rows: repeat(7, 40px);
  grid-gap: 1.5rem;
}
.item {
  background-color: rgb(40, 40, 40);
  border-radius: 5px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  border-left: solid 10px #fff;
}
.item::after,
.item::before {
  content: "";
  width: 5px;
  height: 5px;
  display: block;
  position: absolute;
  border-radius: 50%;
  left: 20px;
  background-color: #fff;
}
.item::after {
  top: 25px;
}
.item::before {
  bottom: 25px;
}
</style>
